package com.red.controller.user;


import com.red.entity.Address;
import com.red.result.Result;
import com.red.service.AddressService;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/address")
@ApiModel(value = "地址接口")
public class AddressController {

    @Autowired
    private AddressService addressService;


    /**
     * 查询当前用户添加的所有地址
     * @return
     */
    @GetMapping
    @ApiModelProperty("查询当前用户添加的所有地址")
    public Result<List<Address>> selectAll(){
        List<Address> addressList = addressService.selectAll();
        return Result.success(addressList);
    }


    /**
     * 添加地址信息
     * @param address
     * @return
     */
    @PostMapping
    @ApiModelProperty("添加地址信息")
    public Result insert(@RequestBody Address address){
        addressService.insert(address);
        return Result.success();
    }


    /**
     * 更改地址状态
     * @param address
     * @return
     */
    @PutMapping()
    @ApiModelProperty("更改地址状态")
    public Result updateStatus(@RequestBody Address address){
        addressService.updateIsDefault(address);
        return Result.success();
    }

    /**
     * 删除地址信息
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiModelProperty("删除地址信息")
    public Result deleteById(@PathVariable Long id){
        addressService.deleteById(id);
        return Result.success();
    }
}
